#include <list>
#include <cstdlib>
#include <iostream>

using namespace std;

void study_list_specific_operations(const list<int>& source)
{
    list<int> l(source);
    list<int> l1(source);
    
    cout << "size of list is " << l.size() << endl;
    l.sort();
    l.unique();  //unique only take effective for the sorted list.
    cout << "size of list after unique is " << l.size() << endl;    
    
    //move data from 
    l.splice(l.end(),l1);
    cout << "size of list after splice is " << l.size() << endl;    
    
    
}

void study_list_move()
{
    list<int> source;
    list<int> target;
    
    cout << "Source: ";
    for (int i=0; i<10; i++)
    {
        source.push_back(i);
        cout << i << " ";
    }
    
    list<int>::iterator it=source.begin(); ++it;
    
    
    target.splice(target.end(), source, it, source.end());
    
    cout << "Source: ";
    for (it=source.begin();it!=source.end(); ++it)
    {
        cout << *it << " ";
    }
    cout << endl;
    
    cout << "Target: ";
    for (it=target.begin();it!=target.end(); ++it)
    {
        cout << *it << " ";
    }
    cout << endl;    
}

int Study_list(int argc, char** argv)
{
	int rc=0;

    list<int> source;
    long long size=100;
    int max_value=20;
    
    for (int i=0; i<size; ++i)
    {
		source.push_back(::rand() % max_value);
    }
    
    //test_list_specific_operations(source);
    study_list_move();
    
    return rc;
}
